package Generics.a03demo3;

import java.util.ArrayList;

public class Test1 {
    public static void main(String[] args) {
        ArrayList<PsCat> list1 = new ArrayList<>();
        list1.add(new PsCat("波斯小白", 2));
        keepCat(list1);

        ArrayList<LhCat> list2 = new ArrayList<>();
        list2.add(new LhCat("狸花小白", 1));
        keepCat(list2);

        ArrayList<TeDog> list3 = new ArrayList<>();
        ArrayList<HsDog> list4 = new ArrayList<>();

    }

    public static void keepCat(ArrayList<? extends Cat> list) {
        for (Cat cat : list) {
            cat.eat();
        }
    }
}

abstract class Animal {
    private String name;
    private int age;

    public Animal() {
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    abstract void eat();

    public String toString() {
        return "Animal{name = " + name + ", age = " + age + "}";
    }

}

abstract class Cat extends Animal {
    public Cat() {
    }

    public Cat(String name, int age) {
        super(name, age);
    }
}

class PsCat extends Cat {
    public PsCat() {
    }

    public PsCat(String name, int age) {
        super(name, age);
    }

    @Override
    void eat() {
        System.out.println("一只叫做" + getName() + "的" + getAge() + "岁的波斯猫");
    }
}

class LhCat extends Cat {
    public LhCat() {
    }

    public LhCat(String name, int age) {
        super(name, age);
    }

    @Override
    void eat() {
        System.out.println("一只叫做" + getName() + "的" + getAge() + "岁的狸花猫");
    }
}

abstract class Dog extends Animal {
    public Dog() {
    }

    public Dog(String name, int age) {
        super(name, age);
    }
}

class TeDog extends Dog {
    public TeDog() {
    }

    public TeDog(String name, int age) {
        super(name, age);
    }

    @Override
    void eat() {
        System.out.println("一只叫做" + getName() + "的" + getAge() + "岁的泰迪");
    }
}

class HsDog extends Dog {
    public HsDog() {
    }

    public HsDog(String name, int age) {
        super(name, age);
    }

    @Override
    void eat() {
        System.out.println("一直叫做" + getName() + "的" + getAge() + "岁的哈士奇");
    }
}